package com.example.leetcode.leetcode;

/**
 * @author zht
 * @date 2021/1/11 19:34
 */
public class Solution221 {
    public static int maximalSquare(char[][] matrix) {
        if (null==matrix||matrix.length==0||matrix[0].length==0){
            return 0;
        }
        int result = 0;
        int row = matrix.length;
        int col= matrix[0].length;
        int [][] dp= new int[row][col];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (matrix[i][j]=='1'){
                    if(i==0||j==0){
                        dp[i][j]=1;
                    }else{
                        dp[i][j]=Math.min(Math.min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1])+1;
                    }
                    result=Math.max(result,dp[i][j]);
                }
            }
        }
        
        return result*result;
    }


    public static void main(String[] args) {
        
    }
}
